<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$cid = $route->GET('c_id');
if ($cid != ""){
	require_once "votes_list.php";
	die;
}

loadPage("head.php");
?>
<h1>Выбрать компанию</h1><br />
<table cellpadding='0' cellspacing='0' class='list'>
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='300px'>Название</td>
		<td width='80px'>Отзывов</td>
		<td width='80px'>Рейтинг</td>
	</tr><?php
		$query = "select `C`.*,count(`V`.`vote_id`) as `votes`,sum(`V`.`mark`) as `rating`
			from `companies` as `C`
			left join `votes` as `V`
			on `C`.`company_id` = `V`.`object_id` and `V`.`object_type` = 'company'
			where `C`.`city_id` = '".$current_admin_city['city_id']."'
			group by `C`.`company_id` having `votes` > 0 order by `name`";
		$companies = $db->getTable($query);
		foreach($companies as $company)
		{
			echo "<tr><td>$company[company_id]</td>";
			echo "<td><a href='/admin/c_votes?c_id=$company[company_id]'>$company[name]</a></td>";
			echo "<td>$company[votes]</td>";
			echo "<td>$company[rating]</td>";
			echo "</tr>";
		}
?></table>

<?php loadPage("footer.php"); ?>